package models

import (
	"time"
	"github.com/astaxie/beego/orm"
)

// 家庭安防的各项数据
type SecInfo struct {
	ID           int64     `json:"id" orm:"pk;column(id)"`
	UserInfo     *UserInfo `orm:"rel(fk)" json:"-"`                              // 数据所属的用户
	Gas          int       `json:"gas" orm:"column(gas)"`               // 气体
	Tem          int       `json:"tem" orm:"column(tem)"`               // 温度
	IllegalEntry bool      `json:"illegal_entry" orm:"column(illegal)"` // 是否有人非法进入
	PickTime     time.Time `json:"pick_time" `                          // 数据的采集时间
}

func (this *SecInfo)Insert() (int64, error){
	return  orm.NewOrm().Insert(this)
}
func (this *SecInfo) Read(cols ... string)error {
	return orm.NewOrm().Read(this,cols...)
}

func PickPass_t( info *UserInfo)( []*SecInfo) {
	var list  []*SecInfo
	orm.NewOrm().QueryTable(SecInfo{}).Filter("pick_time__gte",time.Now().AddDate(0,0,-3).Add(time.Hour * (time.Duration(time.Now().Hour())))).Filter("pick_time__lte",time.Now()).All(&list)
	return list
}